#include "SypEngine.h"

#ifdef CHECKMEM
#include "mmgr.h"
#endif
namespace Syp
{

ShaderProgram::ShaderProgram(const String& file):Resource(file),id(0)
{
	id = Renderer::getRenderer().generateShaderProgram();
}

void ShaderProgram::addShader(Shader* s)
{	
	Renderer::getRenderer().attachShaderToProgram(s,this);
	s->addInstance();
		shaders.push_back(s);	
}

void ShaderProgram::linkShaders()
{
	Renderer::getRenderer().linkShaders(this);
}

ShaderProgram::~ShaderProgram()
{
	std::vector<Shader*>::iterator a = shaders.begin();
	std::vector<Shader*>::iterator b = shaders.end();

	while(a!=b)
	{		
		(*a)->removeInstance();
		++a;
	}
	Renderer::getRenderer().deleteShaderProgram(this);

}
}
